package test;

/**
 * 双重校验锁实现对象单例
 *
 * @author Kent
 * @date 2022/8/5 17:11
 */
public class SingletonClass {
    private static volatile SingletonClass instance = null;

    // 禁止通过构造函数创建对象
    private SingletonClass() {
    }

    private static SingletonClass getInstance() {
        if (instance == null) {
            synchronized (SingletonClass.class) {
                if (instance == null) {
                    instance = new SingletonClass();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        SingletonClass instance = SingletonClass.getInstance();
        System.out.println(instance);
    }
}
